home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: goto
- Date: Thu, 14 Mar 96 17:48:36 GMT
- Organization: none
- Message-ID: <826825716snz@genesis.demon.co.uk>
- References: <Pine.OSF.3.91.960313102715.10701D-100000@io.UWinnipeg.ca> <wpmills.826820253@wpmills>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <wpmills.826820253@wpmills> wpmills@midusa.net "W. Paul Mills" writes:
-
- >Bill Simpson <wsimpson@uwinnipeg.ca> writes:
- >
- >>There was a goto thread lately, and my problem is to state this algorithm
- >>cleanly without gotos (which I think is easy, but my attempts have been
- >>failures).
- >
- >>0. x=0;
- >>1. x+=erand(maxmean);
- >>2. if (urand2()>rate(x)/maxrate)
- >> goto step 1
- >>3. if (x<=XMAX)
- >> {
- >> setdot(x,y,z);
- >> goto step 1
- >> }
- >>explanation:
- >>erand(mean) returns exponential double random number with given mean
- >>urand2() returns uniform double random number between 0 & 1
- >>rate(). well the rate of the Poisson process varies with x
-
- for (x = 0; ; ) {
- x += erand(maxmean);
-
- if (urand2() <= rate(x)/maxrate) {
- if (x > XMAX)
- break;
-
- setdot(x, y, z);
- }
- }
-
- I have reversed the sense of the comparisons here, you will have to decide
- of that has made it less clear.
-
- >x = 0
-
- ;
-
- >do {
- > x += erand(maxmean);
- > if (urand2() > rate(x) / maxrate) continue;
- > setdot(x, y, z);
- > } while ( x < XMAX);
- <=
-
- This doesn't do what was asked (for example the specification will only
- call setdot() if x<=XMAX whereas yours can call it with a larger value).
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-